﻿using System;
using System.Text;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.para.styleenums;

namespace SharpSqlAnalyzer.pp.processor.type.comm
{
	// Token: 0x02000250 RID: 592
	public class CapitalisationProcessor : AbstractProcessor
	{
		// Token: 0x06001325 RID: 4901 RVA: 0x0031CF54 File Offset: 0x0031B154
		public override void beforeProcess(TParseTreeNode node)
		{
			if (node.startToken == null || node.endToken == null)
			{
				return;
			}
			TSourceTokenList container = node.startToken.container;
			int num = node.startToken.posinlist;
			while (num < node.endToken.posinlist + 1 && num < container.size())
			{
				TSourceToken tsourceToken = container.get(num);
				if (tsourceToken.tokentype == ETokenType.ttkeyword)
				{
					if (tsourceToken.DbObjType == EDbObjectType.schema)
					{
						this.processToken(tsourceToken, this.Option.caseDatatype);
					}
					else if (tsourceToken.DbObjType == EDbObjectType.function || tsourceToken.DbObjType == EDbObjectType.library)
					{
						this.processToken(tsourceToken, this.Option.caseFuncname);
					}
					else
					{
						this.processToken(tsourceToken, this.Option.caseKeywords);
					}
				}
				else if (tsourceToken.tokentype == ETokenType.ttidentifier)
				{
					if (tsourceToken.DbObjType == EDbObjectType.schema)
					{
						this.processToken(tsourceToken, this.Option.caseDatatype);
					}
					else if (tsourceToken.DbObjType == EDbObjectType.function || tsourceToken.DbObjType == EDbObjectType.library)
					{
						this.processToken(tsourceToken, this.Option.caseFuncname);
					}
					else
					{
						this.processToken(tsourceToken, this.Option.caseIdentifier);
					}
				}
				else if (tsourceToken.tokentype == ETokenType.ttdqstring)
				{
					this.processToken(tsourceToken, this.Option.caseQuotedIdentifier);
				}
				num++;
			}
		}

		// Token: 0x06001326 RID: 4902 RVA: 0x0031D0A0 File Offset: 0x0031B2A0
		private void processToken(TSourceToken token, TCaseOption type)
		{
			if (token == null || token.astext == null)
			{
				return;
			}
			if (type == TCaseOption.CoUppercase)
			{
				token.astext = token.astext.ToUpper();
				return;
			}
			if (type == TCaseOption.CoLowercase)
			{
				token.astext = token.astext.ToLower();
				return;
			}
			if (type == TCaseOption.CoInitCap)
			{
				StringBuilder stringBuilder = new StringBuilder();
				char[] array = token.astext.ToCharArray();
				char c = ' ';
				foreach (char c2 in array)
				{
					if (c2 != ' ' && c == ' ')
					{
						stringBuilder.Append(char.ToUpper(c2));
					}
					else
					{
						stringBuilder.Append(char.ToLower(c2));
					}
					c = c2;
				}
				token.astext = stringBuilder.ToString();
			}
		}
	}
}
